package com.bosssoft.trainee.nontax.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bosssoft.trainee.nontax.common.Result;
import com.bosssoft.trainee.nontax.entity.po.News;
import com.bosssoft.trainee.nontax.mapper.NewsMapper;
import com.bosssoft.trainee.nontax.service.INewsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author MaYunFei
 * @ProjectName RBAC_BOSS
 * @Description TODO
 * @time 2022/6/14 11:56
 */
@Service
public class NewsServiceImpl extends ServiceImpl<NewsMapper, News> implements INewsService {

    @Resource
    NewsMapper newsMapper;


    @Override
    public Result<?> findPage(Integer pageNum, Integer pageSize, String search) {
        LambdaQueryWrapper<News> wrapper = Wrappers.<News>lambdaQuery().orderByDesc(News::getTime);
        if (StrUtil.isNotBlank(search)) {
            wrapper.like(News::getTitle, search);
        }

        Page<News> newsPage = newsMapper.selectPage(new Page<>(pageNum, pageSize), wrapper);
        return Result.success(newsPage);
    }
}
